package com.ea.admin.service.impl;

import com.ea.admin.service.*;
import com.ea.common.report.ReportFeign;
import com.ea.common.report.pojo.param.GetReportListNewParam;
import com.ea.common.report.pojo.param.GetReportListParam;
import com.ea.common.report.pojo.vo.ReportSimpleInfoListVo;
import com.ea.common.result.BizException;
import com.ea.common.result.ErrorCode;
import com.ea.common.result.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class HistoryReportServiceImpl implements HistoryReportService {

    @Resource
    CompanyPermissionService companyPermissionService;
    @Resource
    DeptPermissionService deptPermissionService;
    @Resource
    PositionService positionService;
    @Resource
    PermissionService permissionService;
    @Resource
    ReportFeign reportFeign;

    @Override
    public ReportSimpleInfoListVo getReportList(Long accountId, List<Long> companyIdList, List<Long> deptIdList, List<Long> positionIdList, List<Integer> warningTypeList, List<Integer> statusList, String name, Date postStartDate, Date postEndDate, Date receiveStartDate, Date receiveEndDate, Date emoAnalyStartDate, Date emoAnalyEndDate, Date heartRateStartDate, Date heartRateEndDate, Integer page, Integer pageSize) {
        // 查询用户权限
        PermissionServiceImpl.PermissionList checked = permissionService
                .checkAndRefreshPermissionList(companyIdList, deptIdList, positionIdList, accountId);
        companyIdList = checked.companyIdList;
        deptIdList = checked.deptIdList;
        positionIdList = checked.positionIdList;

        Result<ReportSimpleInfoListVo> result = reportFeign.getReportListNew(new GetReportListNewParam(
                companyIdList,
                deptIdList,
                positionIdList,
                null,
                warningTypeList,
                statusList,
                postStartDate,
                postEndDate,
                receiveStartDate,
                receiveEndDate,
                emoAnalyStartDate,
                emoAnalyEndDate,
                heartRateStartDate,
                heartRateEndDate,
                name,
                page,
                pageSize
        ));
        if (result.getCode() != ErrorCode.NO_ERROR.getCode()) {
            throw new BizException(ErrorCode.SYSTEM_ERROR);
        }
        return result.getData();
    }
}
